<?php
require_once './component/head.php';
if (!isset($_SESSION['uid'])) header('Location:./login.php');
require_once './component/drawer.php';
require_once './function/conn.php';
$i = 0;
?>
<script type="text/javascript">
    window.onload = function () {
        NoticeOnload();
    };
</script>

<div id="notice_page" class="mdui-container drxs-page">
    <div id="query_notice">
        <div class="mdui-panel" mdui-panel>
            <?php
            $all_notice = QueryNotice();
            while ($notice_info = mysqli_fetch_array($all_notice)) :
                $publisher_name = GetInfoById($notice_info['PublisherId'])['Name'];
                ?>
                <div class="mdui-panel-item">
                    <div class="mdui-panel-item-header">
                        <div class="mdui-panel-item-title"><strong><?php echo $notice_info['NoticeTitle']; ?></strong>
                        </div>
                        <div class="mdui-panel-item-summary">发布时间：<?php echo $notice_info['Time']; ?></div>
                        <div class="mdui-panel-item-summary">发布人：<?php echo $publisher_name; ?></div>
                        <i class="mdui-panel-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
                    </div>
                    <div class="mdui-panel-item-body">
                        <div class="mdui-text-center" style="font-size: 16px"><strong>
                                <?php echo $notice_info['NoticeTitle']; ?></strong>
                        </div> <?php echo $notice_info['NoticeContent']; ?></div>
                </div>
            <?php endwhile; ?>
        </div>
    </div>
    <?php
    if ($_SESSION['utype'] == '管理员' || $_SESSION['utype'] == '教师') {
        $row_num = mysqli_num_rows(mysqli_query($conn, "select * from drxs_notice")) + 1;
        $date = date('Y-m-d');
        $name = GetInfoById($_SESSION['uid'])['Name'];
        ?>
        <div id="release_notice">
            <div class="mdui-card mdui-center">
                <div class="mdui-card-content">
                    <div class="mdui-typo"><h5>请输入以下基本信息，以发布公告。</h5></div>
                    <div class="mdui-divider"></div>
                    <form method="post" action="./function/function.php">
                        <div class="mdui-row">
                            <div class="mdui-col-xs-6">
                                <div class="mdui-textfield mdui-textfield-floating-label">
                                    <label class="mdui-textfield-label">公告Id</label>
                                    <input class="mdui-textfield-input" name="release_notice_id" type="text"
                                           value="<?php echo $row_num; ?>"
                                           required disabled/>
                                </div>
                            </div>
                            <div class="mdui-col-xs-6">
                                <div class="mdui-textfield mdui-textfield-floating-label">
                                    <label class="mdui-textfield-label">发布时间</label>
                                    <input class="mdui-textfield-input" name="release_notice_time" type="text"
                                           value="<?php echo $date; ?>" required disabled/>
                                </div>
                            </div>
                        </div>
                        <div class="mdui-row" style="padding-top: 14px">
                            <div class="mdui-col-xs-6">
                                <label class="mdui-textfield-label">发布者</label>
                                <select class="mdui-select" size="1" name="release_notice_user"
                                        mdui-select="{position: 'bottom'}">
                                    <option value="{$_SESSION['uid']}" selected><?php echo $name; ?></option>
                                </select>
                            </div>
                        </div>
                        <div class="mdui-textfield mdui-textfield-floating-label">
                            <label class="mdui-textfield-label">公告标题</label>
                            <input class="mdui-textfield-input" name="release_notice_title" type="text" required/>
                        </div>
                        <div class="mdui-textfield mdui-textfield-floating-label">
                            <label class="mdui-textfield-label">公告内容</label>
                            <textarea class="mdui-textfield-input" name="release_notice_content" type="text"
                                      required></textarea>
                        </div>
                        <div class="mdui-card-actions">
                            <button type="button" class="mdui-btn mdui-ripple mdui-color-theme-accent mdui-float-right"
                                    id="release_notice_btn"><a class="mdui-text-color-white">提交信息</a>
                            </button>
                            <button class="mdui-btn mdui-ripple mdui-color-theme-accent mdui-float-right" type="reset"
                                    mdui-tooltip="{content: '将清除已填写的数据'}"><a class="mdui-text-color-white">重新填写</a>
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    <?php }
    if ($_SESSION['utype'] == '管理员') { ?>
        <div id="withdraw_notice">
        <!--公告撤回-->

        </div>
    <?php } ?>
</div>

<?php require_once './component/footer.php'; ?>
